package logic

import (
	"context"

	"server_1.0/service/admin/admin"
	"server_1.0/service/admin/internal/svc"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteLogic {
	return &DeleteLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteLogic) Delete(in *admin.DeleteReq) (*admin.QReps, error) {
	code := util.Success
	usersHandle := make([]*admin.Reps, 0)
	count := 0
	err := l.svcCtx.AdminModel.Delete(l.ctx, in.No)
	if err != nil {
		code = util.DelError
	}
	usersHandle = append(
		usersHandle,
		&admin.Reps{
			Code: int64(code),
			No:   in.No,
		})
	count += 1
	return &admin.QReps{
		Count: int64(count),
		QRs:   usersHandle,
	}, nil
}
